/**
 * @file Set.cpp
 * @author Zhu Yihang
 * @brief int类型集合类
 * @date 2022-03-27
 */

#include<bits/stdc++.h>
using namespace std;


const int MAXC = 10; 

class Set{  

private:
	int arr[MAXC];  
	int size;  

public:
	Set(int n = 0);
	Set(int nums[], int len);
	Set(const Set &);
	
	bool add(int x);
	bool del(int x);
	
	Set operator *(const Set &);	
	Set operator +(const Set &);
	
	friend ostream & operator << (ostream & os, const Set &ano);
};

Set::Set(int n){
	size = n;
	for(int i = 0; i < n; ++i){
		arr[i] = 0;
	}
}

Set::Set(int nums[], int len){
	for(int i = 0; i < len; ++i){
		arr[i] = nums[i];
	}
	size = len;
}

Set::Set(const Set &ano){
	this->size = ano.size;
	for(int i = 0; i < this->size; ++i){
		this->arr[i] = ano.arr[i];
	}
}

bool Set::add(int x){
	if(size == MAXC)
		return false;
	
	for(int i = 0; i < size; ++i){
		if(arr[i] == x){
			// printf("%d Already Exists", x);
			return false;
		}
	}
	arr[size++] = x;
	return true;
}

bool Set::del(int x){
	for(int i = 0; i < size; ++i){
		if(arr[i] == x){
			if(size > 1){
				arr[i] = arr[size - 1];
			}
			size--;
			return true;
		} 
	}
	return false;
}

Set Set::operator *(const Set &ano){
	Set ret;
	for(int i = 0; i < this->size; ++i){
		for(int j = 0; j < ano.size; ++j){
			if(this->arr[i] == ano.arr[j]){
				ret.add(this->arr[i]);
				break;
			}
		}
	}
	return ret;
}

Set Set::operator +(const Set &ano){
	Set ret(ano);
	for(int i = 0; i < size && ret.size <= MAXC; ++i){
		ret.add(arr[i]);
	}
	return ret;
}

ostream & operator << (ostream & os, const Set &tar){
	int n = tar.size;
	
	for(int i = 0; i < n; ++i){
		os << tar.arr[i] <<  " \n"[i == n - 1];
	}
	return os;
}

void solve(){
	
	int ax[] = {1, 2, 3, 4};
	int ay[] = {4, 5 ,6, 7};
	Set a(ax, 4);
	Set b(ay, 3);
	
	cout << a + b;
	cout << a * b;
	
}

int main(){
	
    // int t;
    // for(cin >> t; t; --t){
        // solve();
    // }
    
    solve();

    return 0;
}